#include "Transform.h"

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library

#include "Group.h"

CTransform::CTransform(void)
: Child (NULL)
{
	Mtx.Clear();
}

CTransform::CTransform( const float dx, const float dy, const float dz )
{
	Mtx.Translatef( dx, dy, dz );
}

CTransform::CTransform( Matrix4x4 inMTX )
{
	Mtx = inMTX;
}

CTransform::~CTransform(void)
{
}

void CTransform::Draw(void)
{
	if(Child==0) 
		return;
	glPushMatrix();
		glMultMatrixf(Mtx.matrix);
		Child->Draw();
	glPopMatrix();
}

void CTransform::SetGroup(CGroup* theGroup)
{
	this->Child = theGroup;
}

void CTransform::SetTranslate( const float dx, const float dy, const float dz  )
{
	Matrix4x4 TempMtx;
	TempMtx.Translatef( dx, dy, dz );

	Mtx = Mtx * TempMtx;
}

void CTransform::SetRotate( const float angle, const float rx, const float ry, const float rz  )
{
	Mtx.Rotatef( angle, rx, ry, rz );
}

void CTransform::SetScale( const float sx, const float sy, const float sz  )
{
	Mtx.Scalef( sx, sy, sz );
}

void CTransform::ApplyTransform( Matrix4x4 newMTX )
{
	Mtx = Mtx * newMTX;
}

//Get the transformation matrix
Matrix4x4 CTransform::GetTransform(void)
{
	return Mtx;
}